# app.py
from flask import Flask, render_template, make_response

from utils.math_problems import generate_math_problems
from utils.pdf_generator import generate_pdf

app = Flask(__name__)


@app.route('/')
def index():
    return render_template('index.html')


@app.route('/generate/<int:level>')
def generate(level):
    problems = generate_math_problems(level)
    pdf = generate_pdf(problems)
    response = make_response(pdf)
    response.headers['Content-Type'] = 'application/pdf'
    response.headers['Content-Disposition'] = 'attachment; filename=math_problems.pdf'
    return response


if __name__ == '__main__':
    app.run(debug=True)
